package com.pengtu.entity.human;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Attachment;
import com.pengtu.utils.DateUtils;

/**
 * Leave. 请假记录
 */
@Entity
@Table(name = "T_HUMN_LEAVE", schema = "DGJD")
public class Leave extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String deptid;
	private String userid;
	private Date startdate;
	private Date enddate;
	private String clear;
	private String type;
	private String recorder;
	private Date recorddate;
	private String reason; //请假原因
	private Integer vacationCount2; //剩年假--共多少天
	private Integer vacationRemain2; //剩年假--已休多少天
	private Integer vacationAdjust2; //剩年假--本次调多少
	private Integer vacationCount; //年假--共多少天
	private Integer vacationRemain; //年假--已休多少天
	private Integer vacationAdjust; //年假--本次调多少天
	private Integer overtimeCount; //加班-共加多少天
	private Integer overtimeRemain; //加班-已调多少天
	private Integer overtimeAdjust; //加班-本次调多少天
	private String other; //其他
	private String auditor; //部门审核
	private Date auditDate; //审核时间
	private String auditview; //审核意见
	private String verifier; //副站长审核
	private Date verifyDate; //审定时间
	private String verifyview; //复核意见
	private Date signDate; //签发时间
	private String signer; //站长核准
	private String signview; //签发意见
	private Integer days; //天数
	private String remark;
	private String annex;
	private String status;
	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			}); // 附件

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	public Set<Attachment> getAttachmentSet() {

		return attachmentSet;
	}

	public void setAttachmentSet(Set<Attachment> attachmentSet) {
		this.attachmentSet = attachmentSet;
	}

	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}

	public Leave() {
	}

	@Column(name = "DEPTID", length = 48)
	public String getDeptid() {
		return this.deptid;
	}

	public void setDeptid(String deptid) {
		this.deptid = deptid;
	}

	@Column(name = "USERID", length = 48)
	public String getUserid() {
		return this.userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "STARTDATE", length = 7)
	public Date getStartdate() {
		return this.startdate;
	}

	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "ENDDATE", length = 7)
	public Date getEnddate() {
		return this.enddate;
	}

	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}

	@Column(name = "CLEAR", length = 3)
	public String getClear() {
		return this.clear;
	}

	public void setClear(String clear) {
		this.clear = clear;
	}

	@Column(name = "TYPE", length = 3)
	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "RECORDER", length = 200)
	public String getRecorder() {
		return this.recorder;
	}
	
	public void setRecorder(String recorder) {
		this.recorder = recorder;
	}
	
	//计算时间差
	@Transient
	public Integer getDays() {
		
		return DateUtils.betweenDays(this.enddate,this.startdate);
	}

	public void setDays(Integer days) {
		this.days = days;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "RECORDDATE", length = 7)
	public Date getRecorddate() {
		return this.recorddate;
	} 
	
	public void setRecorddate(Date recorddate) {
		this.recorddate = recorddate;
	}

	@Column(name="OTHER",length=500)
	public String getOther() {
		return other;
	}

	public void setOther(String other) {
		this.other = other;
	}

	
	@Column(name="AUDITOR",length=50)
	public String getAuditor() {
		return auditor;
	}

	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name="AUDITDATE")
	public Date getAuditDate() {
		return auditDate;
	}

	public void setAuditDate(Date auditDate) {
		this.auditDate = auditDate;
	}
	
	@Column(name="AUDITVIEW")
	public String getAuditview() {
		return auditview;
	}

	public void setAuditview(String auditview) {
		this.auditview = auditview;
	}
	
	@Column(name="VERIFIER",length=50)
	public String getVerifier() {
		return verifier;
	}

	public void setVerifier(String verifier) {
		this.verifier = verifier;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name="VERIFYDATE")
	public Date getVerifyDate() {
		return verifyDate;
	}

	public void setVerifyDate(Date verifyDate) {
		this.verifyDate = verifyDate;
	}
	
	@Column(name="VERIFYVIEW")
	public String getVerifyview() {
		return verifyview;
	}

	public void setVerifyview(String verifyview) {
		this.verifyview = verifyview;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name="SIGNDATE")
	public Date getSignDate() {
		return signDate;
	}

	public void setSignDate(Date signDate) {
		this.signDate = signDate;
	}
	
	@Column(name="SIGNER",length=50)
	public String getSigner() {
		return signer;
	}

	public void setSigner(String signer) {
		this.signer = signer;
	}
	
	@Column(name="SIGNVIEW")
	public String getSignview() {
		return signview;
	}

	public void setSignview(String signview) {
		this.signview = signview;
	}

	@Column(name = "REMARK", length = 400)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	
	@Column(name="VACATION_COUNT2",length=18)
	public Integer getVacationCount2() {
		return vacationCount2;
	}

	public void setVacationCount2(Integer vacationCount2) {
		this.vacationCount2 = vacationCount2;
	}
	@Column(name="VACATION_REMAIN2",length=18)
	public Integer getVacationRemain2() {
		return vacationRemain2;
	}

	public void setVacationRemain2(Integer vacationRemain2) {
		this.vacationRemain2 = vacationRemain2;
	}
	
	@Column(name="VACATION_ADJUST2",length=18)
	public Integer getVacationAdjust2() {
		return vacationAdjust2;
	}

	public void setVacationAdjust2(Integer vacationAdjust2) {
		this.vacationAdjust2 = vacationAdjust2;
	}
	
	@Column(name="VACATION_COUNT",length=18)
	public Integer getVacationCount() {
		return vacationCount;
	}

	public void setVacationCount(Integer vacationCount) {
		this.vacationCount = vacationCount;
	}

	@Column(name="VACATION_REMAIN",length=18)
	public Integer getVacationRemain() {
		return vacationRemain;
	}

	public void setVacationRemain(Integer vacationRemain) {
		this.vacationRemain = vacationRemain;
	}
	
	@Column(name="VACATION_ADJUST",length=18)
	public Integer getVacationAdjust() {
		return vacationAdjust;
	}

	public void setVacationAdjust(Integer vacationAdjust) {
		this.vacationAdjust = vacationAdjust;
	}

	
	@Column(name="OVERTIME_COUNT",length=18)
	public Integer getOvertimeCount() {
		return overtimeCount;
	}

	public void setOvertimeCount(Integer overtimeCount) {
		this.overtimeCount = overtimeCount;
	}
	
	@Column(name="OVERTIME_REMAIN",length=18)
	public Integer getOvertimeRemain() {
		return overtimeRemain;
	}

	public void setOvertimeRemain(Integer overtimeRemain) {
		this.overtimeRemain = overtimeRemain;
	}
	
	@Column(name="OVERTIME_ADJUST",length=18)
	public Integer getOvertimeAdjust() {
		return overtimeAdjust;
	}

	public void setOvertimeAdjust(Integer overtimeAdjust) {
		this.overtimeAdjust = overtimeAdjust;
	}

	@Column(name = "ANNEX", length = 48)
	public String getAnnex() {
		return this.annex;
	}

	public void setAnnex(String annex) {
		this.annex = annex;
	}

	/**
	 * status
	 *
	 * @return  the status
	 * @since   1.0.0
	 */
	@Column(name="STATUS")
	public String getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
